﻿"<?php
//if (isset($_SESSION['username'])) {
include_once 'header.php';
require_once("../conn.php");
$db = new DBC();
$current_year = date("Y", time());
$current_month = date("n", time());
$year = $current_year;
$month = $current_month;
$page = $_GET['page'];
$id = "";
$name = "";
$url = "";
$code = "";
$answer = "";
$answer1 = "";
$answer2 = "";
$answer3 = "";
$answer4 = "";
$answer5 = "";
$voice1 = "";
$voice2 = "";
$pic = "";
$difficult = "";

if (isset($_GET['code'])) {
    $sql = "SELECT * FROM t_game_question WHERE code = '" . $_GET['code'] . "'";
    $code = $_GET['code'];
    $data = $db->fetchData($sql);
    if (count($data) > 0) {
        $id = $data[0]['id'];
        $name = $data[0]['name'];
        $url = $data[0]['url'];
        $answer = $data[0]['answer'];
        $answer1 = $data[0]['answer1'];
        $answer2 = $data[0]['answer2'];
        $answer3 = $data[0]['answer3'];
        $answer4 = $data[0]['answer4'];
        $answer5 = $data[0]['answer5'];        
        $voice1 = $data[0]['voice1'];
        $voice2 = $data[0]['voice2'];
        $pic = $data[0]['pic'];        
        $isModify = 1;
    }
} else {
    $isModify = 0;    
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>乐知家园</title>
        <style type="text/css">
            <!--
            body,td,th {
                font-family: 微软雅黑;
                font-size: 14px;
                color: #CCCCCC;
            }

            .text{
                height:20px;
            }
            .disable{
                background-color:#CCCCCC;
            }
            -->
        </style>
        <script language="javascript">
            function onSubmitCheck(){
                var flashcode = document.getElementById("flashcode").value;
                var flashname = document.getElementById("flashname").value;
                var type2 = document.getElementsByName("type2[]");
                var version = document.getElementById("version").value;
                var apkurl = document.getElementById("apkurl").value;
                var isok = true;
                var ischecked = false;
                for(var i=0;i<type2.length;i++){
                    if(type2[i].checked==true){
                        ischecked = true;
                        break;
                    }
                }
                if(flashcode==""){
                    alert("\u8bf7输入编码");
                    isok = false;
                }else if(flashname==""){
                    alert("\u8bf7输入名称");
                    isok = false;
                }else if(version==""){
                    alert("\u8bf7输入版本");
                    isok = false;
                }else if(apkurl==""){
                    alert("\u8bf7输入应用地址");
                    isok = false;
                }else if(!ischecked){
                    alert("\u8bf7至少选择一项能力");
                    isok = false;
                }
                if(!isok){
                    event.returnValue = false;
                }
            }
        </script>
        <script type="text/javascript" src="js/jQuery.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                $("#age").change(function(){
                    $.get("getPackByAge.php?age=1", function(data){
                        var obj = jQuery.parseJSON(data);
                        $('#packselect').children().remove().end();
                        $("#packselect").append('<option value="-1">\u65e0</option>');
                        for(var i=0;i<obj.length;i++){
                            var option = "<option value="+obj[i].packid+">"+obj[i].packcode+"-"+obj[i].name+"</option>";
                            $("#packselect").append(option);
                        }
                    });
                });
            });
        </script>
    </head>

    <body>
        <?php
        if (!isset($name)) {
            $name = "";
        }
        if (!isset($url)) {
            $url = "";
        }
        $data = getLevel($code);
        ?>
        <br/>
        <form id="form1" name="form1" method="post" action="question.action.php" enctype="multipart/form-data">
            <table width="50%" border="0" align="center" cellpadding="1" cellspacing="1">
                <!--<tr>
                    <td height="30" bgcolor="#666666"> ID</td>
                    <td bgcolor="#9999FF"><input name="id" type="text" size="50" class="disable" value="<?php echo $id; ?>" disabled="disabled"/>
</td>
                </tr>-->
                <tr>
                    <td height="30" bgcolor="#666666">编号<input name="page" type="hidden" class="text" value="<?php echo $page; ?>"/><input name="isModify" type="hidden" value="<?php echo $isModify; ?>" /></td>
                    <td bgcolor="#9999FF"><input id="oldcode" name="oldcode" type="hidden" class="text" value="<?php echo $code; ?>"/><input id="code" name="code" type="text" size="50" class="text" value="<?php echo $code; ?>"/></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">题目</td>
                    <td bgcolor="#9999FF"><input id="name" name="name" type="text" size="50" class="text" value="<?php echo $name; ?>"/></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">正确答案</td>
                    <td bgcolor="#9999FF"><input name="answer" type="text" size="10" class="text" value="<?php echo $answer; ?>" /></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">错误答案1</td>
                    <td bgcolor="#9999FF"><input name="answer1" type="text" size="10" class="text" value="<?php echo $answer1; ?>" /></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">错误答案2</td>
                    <td bgcolor="#9999FF"><input name="answer2" type="text" size="10" class="text" value="<?php echo $answer2; ?>" /></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">错误答案3</td>
                    <td bgcolor="#9999FF"><input name="answer3" type="text" size="10" class="text" value="<?php echo $answer3; ?>" /></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">错误答案4</td>
                    <td bgcolor="#9999FF"><input name="answer4" type="text" size="10" class="text" value="<?php echo $answer4; ?>" /></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">错误答案5</td>
                    <td bgcolor="#9999FF"><input name="answer5" type="text" size="10" class="text" value="<?php echo $answer5; ?>" /></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">语音1</td>
                    <td bgcolor="#9999FF"><input id="voice1" name="voice1" type="text" size="50" class="text" value="<?php echo $voice1; ?>"/></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">语音2</td>
                    <td bgcolor="#9999FF"><input id="voice2" name="voice2" type="text" size="50" class="text" value="<?php echo $voice2; ?>"/></td>
                </tr>
                <tr>
                    <td height="30" bgcolor="#666666">图片</td>
                    <td bgcolor="#9999FF"><input id="pic" name="pic" type="text" size="50" class="text" value="<?php echo $pic; ?>"/></td>
                </tr>                
                <tr>
                    <td height="30" bgcolor="#666666">类型</td>
                    <td bgcolor="#9999FF">一级类型<input type="text" size="10" class="text" disabled="disabled" value="<?php echo isset($data['one']) ? $data['one'] : ""; ?>"/>
                        二级类型<input type="text" size="10" class="text" disabled="disabled" value="<?php echo isset($data['two']) ? $data['two'] : ""; ?>"/>
                        三级类型<input type="text" size="10" class="text" disabled="disabled" value="<?php echo isset($data['three']) ? $data['three'] : ""; ?>"/></td>
                </tr> 
                <tr>
                    <td height="30" bgcolor="#666666">&nbsp;</td>
                    <td bgcolor="#9999FF">
                        <input type="submit" name="Submit" value="提交" onclick="onSubmitCheck()" />                    </td>
                </tr>
            </table>
        </form>
    </body>
</html>
<?php

function has($type, $num) {
    if (strpos($type, $num) >= 0) {
        return true;
    }
    return false;
}

function getLevel($code) {
    $data = array();
    $letter = substr($code, 1, 1);
    if ($letter == "A" || $letter == "B") {
        $data['one'] = "认知";
        $two = substr($code, 2, 1);
        if ($two == "A") {
            $data['two'] = "交通工具";
        } else if ($two == "B") {
            $data['two'] = "工程车";
        } else if ($two == "C") {
            $data['two'] = "电器";
        } else if ($two == "D") {
            $data['two'] = "职业";
        } else if ($two == "E") {
            $data['two'] = "车标";
        } else if ($two == "F") {
            $data['two'] = "昆虫";
        } else if ($two == "G") {
            $data['two'] = "季节";
        } else if ($two == "H") {
            $data['two'] = "食物";
        } else if ($two == "I") {
            $data['two'] = "水果";
        } else if ($two == "J") {
            $data['two'] = "家具";
        } else if ($two == "K") {
            $data['two'] = "国旗";
        } else if ($two == "L") {
            $data['two'] = "节日";
        } else if ($two == "M") {
            $data['two'] = "乐器";
        } else if ($two == "N") {
            $data['two'] = "表情";
        } else if ($two == "O") {
            $data['two'] = "玩具";
        } else if ($two == "P") {
            $data['two'] = "体育运动";
        } else if ($two == "Q") {
            $data['two'] = "蔬菜";
        } else if ($two == "R") {
            $data['two'] = "形状";
        } else if ($two == "S") {
            $data['two'] = "颜色";
        } else if ($two == "T") {
            $data['two'] = "文具";
        } else if ($two == "U") {
            $data['two'] = "工具";
        } else if ($two == "V") {
            $data['two'] = "";
        } else if ($two == "W") {
            $data['two'] = "动物";
        } else if ($two == "X") {
            $data['two'] = "亲戚";
        } else if ($two == "Y") {
            $data['two'] = "自然";
        } else if ($two == "Z") {
            $data['two'] = "";
        }
        $three = substr($code, 3, 1);
        if ($three == "A") {
            $data['three'] = "名称+外形";
        } else if ($three == "B") {
            $data['three'] = "影子";
        } else if ($three == "C") {
            $data['three'] = "声音";
        } else if ($three == "D") {
            $data['three'] = "其他";
        } else if ($three == "E") {
            $data['three'] = "谜语";
        }
    } else if ($letter == "C") {
        $data['one'] = "常识";
        $two = substr($code, 2, 1);
        if ($two == "A") {
            $data['two'] = "计时单位";
        } else if ($two == "B") {
            $data['two'] = "钟表";
        } else if ($two == "C") {
            $data['two'] = "生活常识";
        } else if ($two == "D") {
            $data['two'] = "组合常识";
            $three = substr($code, 3, 1);
            if ($three == "A") {
                $data['three'] = "相同";
            } else if ($three == "B") {
                $data['three'] = "不同";
            }
        }
    } else if ($letter == "D") {
        $data['one'] = "行为习惯";
        $two = substr($code, 2, 1);
        if ($two == "A") {
            $data['two'] = "选择题";
        } else if ($two == "B") {
            $data['two'] = "判断题";
        }
    } else if ($letter == "E") {
        $data['one'] = "逻辑";
        $two = substr($code, 2, 1);
        if ($two == "A") {
            $data['two'] = "推理";
        } else if ($two == "B") {
            $data['two'] = "观察力";
        }
    } else if ($letter == "F") {
        $data['one'] = "乐知家园";
        $two = substr($code, 2, 1);
        if ($two == "A") {
            $data['two'] = "名称+外形";
        } else if ($two == "B") {
            $data['two'] = "其他";
        }
    }
    return $data;
}

include_once '../footer.php';
//} else {
//    header("login.php");
//}
?>
